import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Demo {

    private DatagramSocket socket = null;

    public Demo(int p) throws SocketException {
        socket = new DatagramSocket(p);
    }

    public void start() throws IOException {
        System.out.println("服务器启动");
        while (true) {

            DatagramPacket p = new DatagramPacket(new byte[4096], 4096);
            socket.receive(p);
            String s = new String(p.getData(), 0, p.getLength());
            String s1 = poccess(s);
            DatagramPacket p1 = new DatagramPacket(s1.getBytes(), 0, s1.getBytes().length, p.getSocketAddress());
            socket.send(p1);
            System.out.printf("[%s:%d] req:%s resp:%s\n", p.getAddress(), p.getPort(), s, s1);

        }
    }

    private String poccess(String s) {
        return s;
    }

    public static void main(String[] args) throws IOException {
        Demo d = new Demo(9099);
        d.start();
    }
}
